package com.ggggeeennn.exam.controller;

import com.ggggeeennn.common.annotation.Log;
import com.ggggeeennn.common.core.controller.BaseController;
import com.ggggeeennn.common.core.domain.AjaxResult;
import com.ggggeeennn.common.core.page.TableDataInfo;
import com.ggggeeennn.common.enums.BusinessType;
import com.ggggeeennn.common.utils.poi.ExcelUtil;
import com.ggggeeennn.exam.domain.ExamManage;
import com.ggggeeennn.exam.domain.PaperParam;
import com.ggggeeennn.exam.service.IExamManageService;
import com.ggggeeennn.question.domain.Question;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 考试管理Controller
 * 
 * @author ggggeeennn
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/module/exam")
public class ExamManageController extends BaseController
{
    @Autowired
    private IExamManageService examManageService;

    /**
     * 查询考试管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:exam:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamManage examManage)
    {

        startPage();
        List<ExamManage> list = examManageService.selectExamManageList(examManage);
        return getDataTable(list);
    }

    /**
     * 导出考试管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:exam:export')")
    @Log(title = "考试管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamManage examManage)
    {
        List<ExamManage> list = examManageService.selectExamManageList(examManage);
        ExcelUtil<ExamManage> util = new ExcelUtil<ExamManage>(ExamManage.class);
        util.exportExcel(response, list, "考试管理数据");
    }

    /**
     * 获取考试管理详细信息
     */
    @GetMapping(value = "/{examCode}")
    public AjaxResult getInfo(@PathVariable("examCode") Long examCode)
    {
        return success(examManageService.selectExamManageByExamCode(examCode));
    }

    /**
     * 新增考试管理
     */
    @PreAuthorize("@ss.hasPermi('module:exam:add')")
    @Log(title = "考试管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamManage examManage)
    {
        return toAjax(examManageService.insertExamManage(examManage));
    }

    /**
     * 修改考试管理
     */
    @PreAuthorize("@ss.hasPermi('module:exam:edit')")
    @Log(title = "考试管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamManage examManage)
    {
        return toAjax(examManageService.updateExamManage(examManage));
    }

    /**
     * 删除考试管理
     */
    @PreAuthorize("@ss.hasPermi('module:exam:remove')")
    @Log(title = "考试管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examCodes}")
    public AjaxResult remove(@PathVariable Long[] examCodes)
    {
        return toAjax(examManageService.deleteExamManageByExamCodes(examCodes));
    }

    //根据考试编号修改试卷是否发布
    @PutMapping("/releaseExam")
    public AjaxResult releaseExam(Integer isPublic,Long examCode)
    {
        return toAjax(examManageService.releaseExam(isPublic,examCode)) ;
    }


    //通过考试编号等信息 获取试卷题列表
    @GetMapping("/paper")
    public TableDataInfo paperList(PaperParam paperParam)
    {
        List<Question> list = examManageService.selectPaperList(paperParam);
        return getDataTable(list);
    }

    //添加试题到试卷
    @PostMapping("/addQuestionToPaper")
    public AjaxResult addQuestionstoPaper( @RequestBody PaperParam paperParam)
    {
        return toAjax(examManageService.addQuestionstoPaper(paperParam));
    }
//
    //在试卷中删除试题,传数组
    @DeleteMapping("/delQuestion")
    public AjaxResult removePaperQuestion(@RequestBody PaperParam paperParam)
    {
        return toAjax(examManageService.removePaperQuestion( paperParam));
    }











}
